﻿using System;
using System.Xml;

namespace YourDataDiscovery.UPSAddressValidation.Message
{
    public sealed class AVAccessRequest
    {
        private String xmlVersion;
        private String accessLicenseNumber;
        private String userId;
        private String password;

        #region Constructors
        public AVAccessRequest()
        {
            this.xmlVersion = "1.0";
            this.accessLicenseNumber = "";
            this.userId = "";
            this.password = "";
        }

        public AVAccessRequest(String accessLicenseNumber, String userId, String password)
        {
            this.xmlVersion = "1.0";
            this.accessLicenseNumber = accessLicenseNumber;
            this.userId = userId;
            this.password = password;
        }

        public AVAccessRequest(String xmlVersion, String accessLicenseNumber, String userId, String password)
            :this(accessLicenseNumber, userId, password)
        {
            this.xmlVersion = xmlVersion;
        }
        #endregion

        #region Properties
        public String XmlVersion
        {
            get { return xmlVersion; }
            set { xmlVersion = value; }
        }

        public String AccessLicenseNumber
        {
            get { return accessLicenseNumber; }
            set { accessLicenseNumber = value; }
        }

        public String UserId
        {
            get { return userId; }
            set { userId = value; }
        }

        public String Password
        {
            get { return password; }
            set { password = value; }
        }
        #endregion

        #region Methods
        public XmlDocument GenerateXmlDocument()
        {
            XmlDocument retXmlDoc = new XmlDocument();

            XmlDeclaration docDeclaration = retXmlDoc.CreateXmlDeclaration(this.xmlVersion, null, null);
            retXmlDoc.AppendChild(docDeclaration);

            XmlElement accessReqElement = retXmlDoc.CreateElement("AccessRequest");
            retXmlDoc.AppendChild(accessReqElement);

            XmlElement accessLicenseNumberElement = retXmlDoc.CreateElement("AccessLicenseNumber");
            accessLicenseNumberElement.InnerText = this.accessLicenseNumber;
            accessReqElement.AppendChild(accessLicenseNumberElement);

            XmlElement userIdElement = retXmlDoc.CreateElement("UserId");
            userIdElement.InnerText = this.userId;
            accessReqElement.AppendChild(userIdElement);

            XmlElement passwordElement = retXmlDoc.CreateElement("Password");
            passwordElement.InnerText = this.password;
            accessReqElement.AppendChild(passwordElement);

            return retXmlDoc;
        }
        #endregion
    }
}
